package com.ioc.business.base.controller;


import cn.hutool.core.util.ObjectUtil;
import com.ioc.business.base.domain.WarehouseUsage;
import com.ioc.business.base.domain.bo.warehouse.usage.WarehouseUsageBo;
import com.ioc.business.base.domain.bo.warehouse.usage.WarehouseUsageQueryBo;
import com.ioc.business.base.service.IWarehouseUsageService;
import com.ioc.business.base.vo.warehouse.usage.WarehouseUsagePageVo;
import com.ioc.business.base.vo.warehouse.usage.WarehouseUsageVo;
import com.ioc.common.annotation.Log;
import com.ioc.common.core.controller.BaseController;
import com.ioc.common.core.domain.AjaxResult;
import com.ioc.common.core.page.TableDataInfo;
import com.ioc.common.core.page.TableVo;
import com.ioc.common.enums.BusinessType;
import com.ioc.common.validate.EditGroup;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 仓库使用情况表 前端控制器
 * </p>
 *
 * @author WeiZhongRong
 * @since 2025-01-09
 */
@RestController
@RequestMapping("/warehouse-usage")
@AllArgsConstructor
public class WarehouseUsageController extends BaseController {

    private final IWarehouseUsageService warehouseUsageService;

    /**
     * 分页查询仓库使用情况列表
     *
     * @param queryBo
     * @return
     * @folder 仓库使用情况/分页查询仓库使用情况列表
     */
    @GetMapping("/list")
    public TableDataInfo selectWarehouseUsagePageList(WarehouseUsageQueryBo queryBo) {
        startPage();
        TableVo<WarehouseUsage, WarehouseUsagePageVo> data = warehouseUsageService.selectWarehouseUsagePageList(queryBo);
        return getDataTable(data);
    }

    /**
     * 查询仓库使用情况详情信息
     *
     * @param warehouseUsageId
     * @return
     * @folder 仓库使用情况/查询仓库使用情况详情信息
     */
    @GetMapping("/{warehouseUsageId}")
    public AjaxResult getWarehouseUsageInfo(@PathVariable("warehouseUsageId") Long warehouseUsageId) {
        WarehouseUsageVo warehouseUsageVo = warehouseUsageService.selectWarehouseUsageById(warehouseUsageId);
        if (ObjectUtil.isEmpty(warehouseUsageVo)) {
            return error("数据不存在!");
        }
        return success(warehouseUsageVo);
    }
    

    /**
     * 编辑仓库使用情况
     *
     * @param bo
     * @return
     * @folder 仓库使用情况/编辑仓库使用情况
     */
    @PostMapping("/edit")
    @Log(title = "仓库使用情况", businessType = BusinessType.UPDATE)
    public AjaxResult updateWarehouseUsage(@RequestBody @Validated(EditGroup.class) WarehouseUsageBo bo) {
        return toAjax(warehouseUsageService.updateWarehouseUsage(bo));
    }

    /**
     * 删除仓库使用情况
     *
     * @param idList
     * @return
     * @folder 仓库使用情况/删除仓库使用情况
     */
    @Log(title = "仓库使用情况", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public AjaxResult remove(@RequestBody List<Long> idList) {
        return toAjax(warehouseUsageService.removeWarehouseUsage(idList));
    }

}
